﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using Common;
using 包覆门.OperatorManager;
using 包覆门.MenxingManager;
using 包覆门.OrderManager;
using 包覆门.LineManager;
using 包覆门.KaikongManager;
using 包覆门.ColorManager;
using 包覆门.GlassManager;
using 包覆门.HanderManager;
using 包覆门.HingeManager;
using 包覆门.DealerManager;
using 包覆门.MxExpression;
using 包覆门.PackageManager;
using 包覆门.OtherDecManager;

namespace 包覆门
{
    public partial class mainform : Form
    {
        public mainform()
        {
            InitializeComponent();
            
        }
        //载入事件
        private void mainform_Load(object sender, EventArgs e)
        {
            //loginForm lf = new loginForm();
            //label2.Text = RemeberName.Username;
            //lf.Show();
            if (!ValidateRote())
            {
                this.btncdlist.Enabled = false;
                this.btnColor.Enabled = false;
                this.btnlr.Enabled = true;
                this.btnGlass.Enabled = false;
                this.btnMenxing.Enabled = false;
                this.btnWeihu.Enabled = false;
                this.button1.Enabled = false;
                this.button2.Enabled = false;
                this.btnHander.Enabled = false;
                this.btnHinge.Enabled = false;
                this.btnDealer.Enabled = false;
                this.btnMxExpression.Enabled = false;
                this.btnpackage.Enabled = false;
                this.btnOtherDec.Enabled = false;

            }
            else {
                this.btncdlist.Enabled = true;
                this.btnColor.Enabled = true;
                this.btnlr.Enabled = true;
                this.btnGlass.Enabled = true;
                this.btnMenxing.Enabled = true;
                this.btnWeihu.Enabled = true;
                this.button1.Enabled = true;
                this.button2.Enabled = true;
                this.btnHander.Enabled = true;
                this.btnHinge.Enabled = true;
                this.btnDealer.Enabled = true;
                this.btnMxExpression.Enabled = true;
                this.btnpackage.Enabled = true;
                this.btnOtherDec.Enabled = true;
            }

        }
       // public static addorder adr = null;
        public static OrderList ol = null;
        //录入订单
        private void btnlr_Click(object sender, EventArgs e)
        {
            
            if (ol == null)
            {
                ol = new OrderList();
                ol.StartPosition = FormStartPosition.CenterScreen;
                ol.WindowState = FormWindowState.Maximized;
                ol.Show();
            }
            else
            {
                ol.Activate();
                ol.WindowState = FormWindowState.Maximized;
            }
            this.WindowState = FormWindowState.Minimized;
        }

        //public static orderlist ol = null;
        public static MenxingList  ml= null;
        //订单列表
        private void btnlist_Click(object sender, EventArgs e)
        {
            if (ml == null)
            {
                ml = new MenxingList();
                ml.StartPosition = FormStartPosition.CenterScreen;
                ml.WindowState = FormWindowState.Normal;
                ml.Show();
            }
            else
            {
                ml.Activate();
                ml.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        //public static cdlist cl = null; 
        //装饰线条
        public static LineList ll = null;
        private void btncdlist_Click(object sender, EventArgs e)
        {
            if (ll == null)
            {
                ll = new LineList();
                ll.StartPosition = FormStartPosition.CenterScreen;
                ll.WindowState = FormWindowState.Normal;
                ll.Show();
            }
            else {
                ll.Activate();
                ll.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        
        //提交数据
        private void btnsubmit_Click(object sender, EventArgs e)
        {
            MessageBox.Show("暂无数据");
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否确认退出程序？", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                // 关闭所有的线程
                this.deskNotify.Dispose();
                this.Dispose();
                this.Close();
            }
        }
        //public static TestForm tf= null;
        public static accountForm af = null;
        private void button2_Click(object sender, EventArgs e)
        {
            if (af == null)
            {
               // tf = new TestForm();
                af = new accountForm();
                af.StartPosition = FormStartPosition.CenterScreen;
                af.WindowState = FormWindowState.Normal;
                af.Show();
            }
            else {
                af.Activate();
                af.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        public static KaikongList kl = null;
        private void button1_Click(object sender, EventArgs e)
        {
            //TestView tv = new TestView();
            //tv.Show();
            if (kl == null)
            {
                // tf = new TestForm();
                kl = new KaikongList();
                kl.StartPosition = FormStartPosition.CenterScreen;
                kl.WindowState = FormWindowState.Normal;
                kl.Show();
            }
            else
            {
                kl.Activate();
                kl.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        public static OperatorList om = null;
        private void btnWeihu_Click(object sender, EventArgs e)
        {
            if (om == null)
            {
                // tf = new TestForm();
                om = new OperatorList();
                om.StartPosition = FormStartPosition.CenterScreen;
                om.WindowState = FormWindowState.Normal;
                om.Show();
            }
            else
            {
                om.Activate();
                om.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
       // public static DotonView tv = null;

        public static ColorList cl = null;
        private void btnColor_Click(object sender, EventArgs e)
        {
            if (cl == null)
            {
                // tf = new TestForm();
                cl = new ColorList();
                cl.StartPosition = FormStartPosition.CenterScreen;
                cl.WindowState = FormWindowState.Normal;
                cl.Show();
            }
            else
            {
                cl.Activate();
                cl.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
           //MessageBox.Show("正在努力开发中，请等待更新");
            //return;
        }
        public static GlassList gl = null;
        private void btnGlass_Click(object sender, EventArgs e)
        {
            if (gl == null)
            {
                // tf = new TestForm();
                gl = new GlassList();
                gl.StartPosition = FormStartPosition.CenterScreen;
                gl.WindowState = FormWindowState.Normal;
                gl.Show();
            }
            else
            {
                gl.Activate();
                gl.WindowState = FormWindowState.Normal;
            }
            //MessageBox.Show("正在努力开发中，请等待更新");
            //return;

            this.WindowState = FormWindowState.Minimized;
        }
        public bool ValidateRote() {
            bool flag = true;
            if (!RemeberName.IsAdmin.Equals("1")) {
                return false;
            }
            return flag;
        }
        //窗口变化
        private void mainform_SizeChanged(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                //隐藏任务栏区图标
                this.ShowInTaskbar = false;
                //图标显示在托盘区
                deskNotify.Visible = true;
               
            }
        }

        private void deskNotify_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                //还原窗体显示    
                WindowState = FormWindowState.Normal;
                //激活窗体并给予它焦点
                this.Activate();
                //任务栏区显示图标
                this.ShowInTaskbar = true;
                //托盘区图标隐藏
                deskNotify.Visible = false;
            }
        }
        //订单管理
        private void OrderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            if (ol == null)
            {
                ol = new OrderList();
                ol.StartPosition = FormStartPosition.CenterScreen;
                ol.WindowState = FormWindowState.Maximized;
                ol.Show();
            }
            else
            {
                ol.Activate();
                ol.WindowState = FormWindowState.Maximized;
            }
        }
        //门型管理
        private void MenxingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (ml == null)
            {
                ml = new MenxingList();
                ml.StartPosition = FormStartPosition.CenterScreen;
                ml.WindowState = FormWindowState.Normal;
                ml.Show();
            }
            else
            {
                ml.Activate();
                ml.WindowState = FormWindowState.Normal;
            }
        }
        //装饰线条
        private void ZsxtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (ll == null)
            {
                ll = new LineList();
                ll.StartPosition = FormStartPosition.CenterScreen;
                ll.WindowState = FormWindowState.Normal;
                ll.Show();
            }
            else
            {
                ll.Activate();
                ll.WindowState = FormWindowState.Normal;
            }
        }
        //颜色管理
        private void ColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (cl == null)
            {
                // tf = new TestForm();
                cl = new ColorList();
                cl.StartPosition = FormStartPosition.CenterScreen;
                cl.WindowState = FormWindowState.Normal;
                cl.Show();
            }
            else
            {
                cl.Activate();
                cl.WindowState = FormWindowState.Normal;
            }
        }
        //用户管理
        private void UserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (om == null)
            {
                // tf = new TestForm();
                om = new OperatorList();
                om.StartPosition = FormStartPosition.CenterScreen;
                om.WindowState = FormWindowState.Normal;
                om.Show();
            }
            else
            {
                om.Activate();
                om.WindowState = FormWindowState.Normal;
            }
        }
        //开孔
        private void KaikongToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (kl == null)
            {
                // tf = new TestForm();
                kl = new KaikongList();
                kl.StartPosition = FormStartPosition.CenterScreen;
                kl.WindowState = FormWindowState.Normal;
                kl.Show();
            }
            else
            {
                kl.Activate();
                kl.WindowState = FormWindowState.Normal;
            }
        }
        //打款账户
        private void AccountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (af == null)
            {
                // tf = new TestForm();
                af = new accountForm();
                af.StartPosition = FormStartPosition.CenterScreen;
                af.WindowState = FormWindowState.Normal;
                af.Show();
            }
            else
            {
                af.Activate();
                af.WindowState = FormWindowState.Normal;
            }
        }
        //芯板玻璃
        private void GlassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (gl == null)
            {
                // tf = new TestForm();
                gl = new GlassList();
                gl.StartPosition = FormStartPosition.CenterScreen;
                gl.WindowState = FormWindowState.Normal;
                gl.Show();
            }
            else
            {
                gl.Activate();
                gl.WindowState = FormWindowState.Normal;
            }
        }
        //退出
        private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否确认退出程序？", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                this.deskNotify.Dispose();
                // 关闭所有的线程
                this.Dispose();
                this.Close();
            }
        }

        private void btnMin_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }

        private Point mouseOffset; //记录鼠标指针的坐标 
        private bool isMouseDown = false; //记录鼠标按键是否按下 

        private void mainform_MouseDown(object sender, MouseEventArgs e)
        {
            int xOffset;
            int yOffset;

            if (e.Button == MouseButtons.Left)
            {
                xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                yOffset = -e.Y - SystemInformation.CaptionHeight -
                SystemInformation.FrameBorderSize.Height;
                mouseOffset = new Point(xOffset, yOffset);
                isMouseDown = true;
            }
        }

        private void mainform_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                Location = mousePos;
            }
        }

        private void mainform_MouseUp(object sender, MouseEventArgs e)
        {
            // 修改鼠标状态isMouseDown的值 
            // 确保只有鼠标左键按下并移动时，才移动窗体 
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }
        //拉手管理
        public static HanderList hl = null;
        private void btnHander_Click(object sender, EventArgs e)
        {
           
            if (hl == null)
            {
                hl = new HanderList();
                hl.StartPosition = FormStartPosition.CenterScreen;
                hl.WindowState = FormWindowState.Normal;
                hl.Show();
            }
            else
            {
                hl.Activate();
                hl.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        //铰链管理
        public static HingeList hinge = null;
        private void btnHinge_Click(object sender, EventArgs e)
        {
           
            if (hinge == null)
            {
                hinge = new HingeList();
                hinge.StartPosition = FormStartPosition.CenterScreen;
                hinge.WindowState = FormWindowState.Normal;
                hinge.Show();
            }
            else
            {
                hinge.Activate();
                hinge.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        //经销商管理
        public static DealerList dl = null;
        private void btnDealer_Click(object sender, EventArgs e)
        {
           
            if (dl == null)
            {
                dl = new DealerList();
                dl.StartPosition = FormStartPosition.CenterScreen;
                dl.WindowState = FormWindowState.Normal;
                dl.Show();
            }
            else
            {
                dl.Activate();
                dl.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        //经销商toolbar
        private void tsbDealer_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (dl == null)
            {
                dl = new DealerList();
                dl.StartPosition = FormStartPosition.CenterScreen;
                dl.WindowState = FormWindowState.Normal;
                dl.Show();
            }
            else
            {
                dl.Activate();
                dl.WindowState = FormWindowState.Normal;
            }
        }
        //拉手toolbar
        private void tsbHander_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (hl == null)
            {
                hl = new HanderList();
                hl.StartPosition = FormStartPosition.CenterScreen;
                hl.WindowState = FormWindowState.Normal;
                hl.Show();
            }
            else
            {
                hl.Activate();
                hl.WindowState = FormWindowState.Normal;
            }
        }
        //铰链toolbar
        private void tsbHinge_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (hinge == null)
            {
                hinge = new HingeList();
                hinge.StartPosition = FormStartPosition.CenterScreen;
                hinge.WindowState = FormWindowState.Normal;
                hinge.Show();
            }
            else
            {
                hinge.Activate();
                hinge.WindowState = FormWindowState.Normal;
            }
        }
        public static MxExpressionList mxlist = null;
        private void btnMxExpression_Click(object sender, EventArgs e)
        {
            if (mxlist == null)
            {
                mxlist = new MxExpressionList();
                mxlist.StartPosition = FormStartPosition.CenterScreen;
                mxlist.WindowState = FormWindowState.Normal;
                mxlist.Show();
            }
            else
            {
                mxlist.Activate();
                mxlist.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }

        private void tbsMxExpression_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (mxlist == null)
            {
                mxlist = new MxExpressionList();
                mxlist.StartPosition = FormStartPosition.CenterScreen;
                mxlist.WindowState = FormWindowState.Normal;
                mxlist.Show();
            }
            else
            {
                mxlist.Activate();
                mxlist.WindowState = FormWindowState.Normal;
            }
        }
        //包装管理
        public static PackageList pl = null;
        private void btnpackage_Click(object sender, EventArgs e)
        {
            if (pl == null)
            {
                pl = new PackageList();
                pl.StartPosition = FormStartPosition.CenterScreen;
                pl.WindowState = FormWindowState.Normal;
                pl.Show();
            }
            else
            {
                pl.Activate();
                pl.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }
        //包装管理
        private void tsbpackage_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (pl == null)
            {
                pl = new PackageList();
                pl.StartPosition = FormStartPosition.CenterScreen;
                pl.WindowState = FormWindowState.Normal;
                pl.Show();
            }
            else
            {
                pl.Activate();
                pl.WindowState = FormWindowState.Normal;
            }
        }
        //附加装饰管理管理
        public static OtherDecList od = null;
        private void btnOtherDec_Click(object sender, EventArgs e)
        {
            if (od == null)
            {
                od = new OtherDecList();
                od.StartPosition = FormStartPosition.CenterScreen;
                od.WindowState = FormWindowState.Normal;
                od.Show();
            }
            else
            {
                od.Activate();
                od.WindowState = FormWindowState.Normal;
            }
            this.WindowState = FormWindowState.Minimized;
        }

        private void tspOtherDec_Click(object sender, EventArgs e)
        {
            if (!ValidateRote())
            {
                MessageBox.Show("您没有此权限");
                return;
            }
            if (od == null)
            {
                od = new OtherDecList();
                od.StartPosition = FormStartPosition.CenterScreen;
                od.WindowState = FormWindowState.Normal;
                od.Show();
            }
            else
            {
                od.Activate();
                od.WindowState = FormWindowState.Normal;
            }
        }

    }
}
